$(document).ready(function(){
    window.operateEvents = {
        "click #editRow":function(e, value, row, index){
            // console.log(index);
            var select = $("#user").bootstrapTable(
              "getSelections"
            );
            console.log(select);
        },
        "click #deleteRow":function(e, value, row, index){
            $(this).parent().parent().remove();
        }
    }
    $("#user").bootstrapTable({
        url:"http://127.0.0.8/index.php/index/Index/page",
        columns:[
            {
                field:"select",
                title:"全选",
                checkbox:true
            },
            {
                field:'id',
                title:'id',
                visible:false
            },
            {
                field:'name',
                title:'name'
            },
            {
                field:'age',
                title:'age'
            },
            {
                field:'work',
                title:'work'
            },
            {
                field:'mobile',
                title:'mobile'
            },
            {
                field:'phone',
                title:'phone'
            },
            {
                field:'te',
                title:'备注'
            },
            {
                field:'text',
                title:'填写/修改备注   ',
                formatter:te,
                events:{
                    "blur .remark":function(e, value, row, index){
                        var valueSelected = $(this).val();
                        console.log(valueSelected);
                        $('#user').bootstrapTable('updateCell', {
                            index: index,
                            field: 'te',
                            value: valueSelected
                        });
                    }
                }
            },
            {
                field:'Button',
                title:'操作',
                events:operateEvents,
                formatter:addButtons,
            },
        ],
        striped:true,
        sortName:'id',                    // 排序字段名
        sortOrder:'asc',                   // 升降序，默认升序
        icons:{
            paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down',
            paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up',
            refresh: 'glyphicon-refresh icon-refresh',
            toggle: 'glyphicon-list-alt icon-list-alt',
            columns: 'glyphicon-th icon-th',
            detailOpen: 'glyphicon-plus icon-plus',
            detailClose: 'glyphicon-minus icon-minus',
        },
        pagination:true,                    // 分页
        onlyInfoPagination:false,           // 只显示数据量
        pageSize:3,                         // 每页数据量
        pageList:[3,6,9],                   // 可选择每页数据量
        search:false,                        // 显示搜索
        selectItemName:'id',
        showHeader:true,                    // 显示头
        showColumns:true,                   // 显示列下拉框
        showRefresh:true,                   // 显示刷新
        showToggle:true,                    // 切换试图
        showPaginationSwitch:true,          // 显示分页切换按钮
        idField:'id',                       // 指定主键
        uniqueId:'id',                      // 设置每一行唯一标识符
        detailView:false,                    // 显示详细页面
        searchAlign:'left',                // 搜索框位置
        buttonsAlign:'right',                 // 按钮位置
        paginationVAlign:'bottom',
        paginationHAlign:'right',
        paginationPreText:'上一页',
        paginationNextText:'下一页',
        toolbar:'#toolbar',
        toolbarAlign:'left',
        sidePagination:'server',            // 客户端还是服务端分页
        queryParams: function queryParams(params) {
            return {
                pageNumber: params.offset,
                pageSize: params.limit,
                name:$("#search_name").val(),
                mobile:$("#search_mobile").val()
            };
        },
    });
    //查询按钮事件
    $('#search_btn').click(function(){
        $('#user').bootstrapTable('refresh', {url: 'http://127.0.0.8/index.php/index/Index/page'});
    });
    //添加按钮
    function addButtons(){
        return [
            "<button type='button' id='editRow' class='btn btn-success btn-xs'>编辑</button>&nbsp;&nbsp;",
            "<button type='button' id='deleteRow' class='btn btn-danger btn-xs'>删除</button>",
        ].join("")
    }
    function te(){
        return [
            "<textarea class='remark'></textarea>",
        ].join("")
    }

})